/*******************************************************************************
 *
 * Pentaho Big Data
 *
 * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.pentaho.runtime.test.module.impl;

import org.pentaho.runtime.test.RuntimeTest;
import org.pentaho.runtime.test.module.RuntimeTestModuleResults;
import org.pentaho.runtime.test.result.RuntimeTestEntrySeverity;
import org.pentaho.runtime.test.result.RuntimeTestResult;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by bryan on 8/11/15.
 */
public class RuntimeTestModuleResultsImpl implements RuntimeTestModuleResults {
  private final String name;
  private final List<RuntimeTestResult> runtimeTestResults;
  private final Set<RuntimeTest> runningTests;
  private final Set<RuntimeTest> outstandingTests;
  private final RuntimeTestEntrySeverity maxSeverity;

  public RuntimeTestModuleResultsImpl( String name, List<RuntimeTestResult> runtimeTestResults,
                                       Set<RuntimeTest> runningTests, Set<RuntimeTest> outstandingTests ) {
    this.name = name;
    this.runningTests = Collections.unmodifiableSet( new HashSet<>( runningTests ) );
    this.outstandingTests = Collections.unmodifiableSet( new HashSet<>( outstandingTests ) );
    this.runtimeTestResults = Collections.unmodifiableList( new ArrayList<>( runtimeTestResults ) );
    this.maxSeverity = RuntimeTestEntrySeverity.maxSeverityResult( runtimeTestResults );
  }

  @Override public String getName() {
    return name;
  }

  @Override public List<RuntimeTestResult> getRuntimeTestResults() {
    return runtimeTestResults;
  }

  @Override public RuntimeTestEntrySeverity getMaxSeverity() {
    return maxSeverity;
  }

  @Override public Set<RuntimeTest> getRunningTests() {
    return runningTests;
  }

  @Override public Set<RuntimeTest> getOutstandingTests() {
    return outstandingTests;
  }

  //OperatorWrap isn't helpful for autogenerated methods
  //CHECKSTYLE:OperatorWrap:OFF
  @Override public String toString() {
    return "RuntimeTestModuleResultsImpl{" +
      "getName='" + name + '\'' +
      ", runtimeTestResults=" + runtimeTestResults +
      ", runningTests=" + runningTests +
      ", outstandingTests=" + outstandingTests +
      ", maxSeverity=" + maxSeverity +
      '}';
  }
  //CHECKSTYLE:OperatorWrap:ON
}
